package vip.xiaonuo.supplier.modular.setting.reporttype.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.setting.reporttype.entity.PublicReportType;
import vip.xiaonuo.supplier.modular.setting.reporttype.param.PublicReportTypeAddParam;
import vip.xiaonuo.supplier.modular.setting.reporttype.param.PublicReportTypeEditParam;
import vip.xiaonuo.supplier.modular.setting.reporttype.param.PublicReportTypeIdParam;
import vip.xiaonuo.supplier.modular.setting.reporttype.param.PublicReportTypePageParam;
import vip.xiaonuo.supplier.modular.setting.reporttype.service.PublicReportTypeService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 报表类型控制器
 *
 * @author Mr.wu
 * @date  2025/04/03 09:31
 */
@Tag(name = "报表类型控制器")
@RestController
@Validated
public class PublicReportTypeController {

    @Resource
    private PublicReportTypeService publicReportTypeService;

    /**
     * 获取报表类型分页
     *
     * @author Mr.wu
     * @date  2025/04/03 09:31
     */
    @Operation(summary = "获取报表类型分页")
    @SaCheckPermission("/supplier/setting/reporttype/page")
    @GetMapping("/supplier/setting/reporttype/page")
    public CommonResult<Page<PublicReportType>> page(PublicReportTypePageParam publicReportTypePageParam) {
        return CommonResult.data(publicReportTypeService.page(publicReportTypePageParam));
    }

    /**
     * 添加报表类型
     *
     * @author Mr.wu
     * @date  2025/04/03 09:31
     */
    @Operation(summary = "添加报表类型")
    @CommonLog("添加报表类型")
    @SaCheckPermission("/supplier/setting/reporttype/add")
    @PostMapping("/supplier/setting/reporttype/add")
    public CommonResult<String> add(@RequestBody @Valid PublicReportTypeAddParam publicReportTypeAddParam) {
        publicReportTypeService.add(publicReportTypeAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑报表类型
     *
     * @author Mr.wu
     * @date  2025/04/03 09:31
     */
    @Operation(summary = "编辑报表类型")
    @CommonLog("编辑报表类型")
    @SaCheckPermission("/supplier/setting/reporttype/edit")
    @PostMapping("/supplier/setting/reporttype/edit")
    public CommonResult<String> edit(@RequestBody @Valid PublicReportTypeEditParam publicReportTypeEditParam) {
        publicReportTypeService.edit(publicReportTypeEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除报表类型
     *
     * @author Mr.wu
     * @date  2025/04/03 09:31
     */
    @Operation(summary = "删除报表类型")
    @CommonLog("删除报表类型")
    @SaCheckPermission("/supplier/setting/reporttype/delete")
    @PostMapping("/supplier/setting/reporttype/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<PublicReportTypeIdParam> publicReportTypeIdParamList) {
        publicReportTypeService.delete(publicReportTypeIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取报表类型详情
     *
     * @author Mr.wu
     * @date  2025/04/03 09:31
     */
    @Operation(summary = "获取报表类型详情")
    @SaCheckPermission("/supplier/setting/reporttype/detail")
    @GetMapping("/supplier/setting/reporttype/detail")
    public CommonResult<PublicReportType> detail(@Valid PublicReportTypeIdParam publicReportTypeIdParam) {
        return CommonResult.data(publicReportTypeService.detail(publicReportTypeIdParam));
    }
}
